import React, { useState } from 'react';
import {
    Button,
    DatePicker,
    Form,
    Input,
    message,

} from 'antd';
import { addCheck } from '../../../../../../api/csy/api'

const formItemLayout = {
    labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
    },
    wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
    },
};

const App: React.FC = () => {
    const [form] = Form.useForm();

    const [year, setYear] = useState<string>('')
    const [object, setObject] = useState<string>('')
    const [startTime, setStartTime] = useState<string>('')
    const [endTime, setEndTime] = useState<string>('')
    const [name1, setName] = useState<string>('')
    const [contet, setContet] = useState<string>('')
    const [timer, setTimer] = useState<string>('')
    const [array, setArray] = useState<[string]>([''])
    const [jianTime, setJianTime] = useState<string>('')


    const dian = () => {
        console.log(year, object, startTime, endTime, name1, contet, timer, array, jianTime)
        addCheck({
            year: year,
            object: object,
            startTime: startTime,
            endTime: endTime,
            name1: name1,
            contet: contet,
            timer: timer,
            array: array,
            jianTime: jianTime
        }).then((res) => {
            if (res.data.code == 200) {
                message.success('添加成功')
            }
        })
    }
    return (
        <Form
            {...formItemLayout}
            form={form}
            style={{ maxWidth: 600 }}
        >
            <Form.Item label="年份" name="year" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={year} onChange={(e) => setYear(e.target.value)} />
            </Form.Item>
            <Form.Item label="责任对象" name="object" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={object} onChange={(e) => setObject(e.target.value)} />
            </Form.Item>
            <Form.Item
                label="计划开始时间"
                name="startTime"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <DatePicker onChange={(e) => setStartTime(e as unknown as string)} />
            </Form.Item>

            <Form.Item
                label="计划结束时间"
                name="endTime"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <DatePicker onChange={(e) => setEndTime(e as unknown as string)} />
            </Form.Item>
            <Form.Item
                label="检查说明"
                name="contet"
                rules={[{ message: '请输入检查说明' }]}
            >
                <Input.TextArea onChange={(e) => setContet(e.target.value)} />
            </Form.Item>
            <Form.Item label="任务下达人" name="name1" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={name1} onChange={(e) => setName(e.target.value)} />
            </Form.Item>
            <Form.Item
                label="任务下达时间"
                name="timer"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <DatePicker onChange={(e) => setTimer(e as unknown as string)} />
            </Form.Item>
            <Form.Item
                label="检查组成员"
                name="array"
                rules={[{ message: '请输入检查说明' }]}
            >
                <Input.TextArea onChange={(e) => setArray([e.target.value])} />
            </Form.Item>
            <Form.Item
                label="检查时间"
                name="jianTime"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <DatePicker onChange={(e) => setJianTime(e as unknown as string)} />
            </Form.Item>
            <Form.Item wrapperCol={{ offset: 6, span: 16 }}>
                <Button type="primary" htmlType="submit" onClick={dian}>
                    Submit
                </Button>
            </Form.Item>
        </Form>
    );
};

export default App;